/**
 * @author		Ben Layet
 * @version 	0.1
 * @date		29 Oct 2008
 * @copyright 	� Canon Europa N. V. 2004
 */
package org.ignoramus.application.view.rcp;

import java.io.File;

import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.jface.action.Action;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;

/**
 * 
 */
public class OpenFileAction extends Action
{


	public OpenFileAction()
	{
		setId("Ignoramus.openTestFile");
		// Associate the action with a pre-defined command, to allow key
		// bindings.
		setActionDefinitionId("Ignoramus.openTestFile");
	}

	public void run()
	{

		File fileToOpen = new File(System.getProperty("user.home") + "/lesson.ign");

		if (fileToOpen.exists() && fileToOpen.isFile())
		{
			IFileStore fileStore = EFS.getLocalFileSystem().getStore(fileToOpen.toURI());
			IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();

			try
			{
				IDE.openEditorOnFileStore(page, fileStore);
			}
			catch (PartInitException e)
			{
				e.printStackTrace();
			}
		}
		else
		{
			// Do something if the file does not exist
		}
	}
}
